﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using SAPBoAddon.B1Assistant;
using System.Xml;

namespace BoAddonBiz_FreightForwarder.SystemForm
{
    /// <summary>
    /// 业务伙伴主数据
    /// </summary>
    class B1Form_BusinessPartner : SAPBoAddon.B1Form
    {
        string Value = string.Empty;
        string CardCode = string.Empty;
        string CardCodeLineNum = string.Empty;
        string AdresType = string.Empty;
        string Address = string.Empty;
        IList<AddressInfo> AddressList = new List<AddressInfo>();
        public B1Form_BusinessPartner()
        {
            this.frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_BusinessPartner_frm_ItemEvent);
            this.frm_FormDataEvent += new SAPBoAddon.IB1FormEvents.B1FormDataEventEventHandler(B1Form_BusinessPartner_frm_FormDataEvent);
            this.frm_MenuEvent += new SAPBoAddon.IB1FormEvents.B1MenuEventEventHandler(B1Form_BusinessPartner_frm_MenuEvent);
        }
        #region  事件处理
        void B1Form_BusinessPartner_frm_FormDataEvent(SAPBoAddon.B1AddonBase.B1BusinessObjectInfo pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
            }
            else
            {
                if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_LOAD)
                {
                    InitPB();
                }
                if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE)
                {
                    UpdateAddressInfo();
                }
            }
        }

        void B1Form_BusinessPartner_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
                if (pVal.ItemUID == "69" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK)
                {
                    GetAddressInfo(pVal.Row);
                }
                if ((pVal.ItemUID == "Address" || (pVal.ItemUID == "178" && pVal.ColUID == "1")) && pVal.EventType == SAPbouiCOM.BoEventTypes.et_VALIDATE)
                {
                    SetAddressInfo();
                }
                if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST)
                {
                    if (IsManager(SBOCompany.UserSignature))
                        return;
                    var CFL = CurrentFormEx.ChooseFromLists.Item("-1");
                    if (CFL.ObjectType == "2")
                    {
                        IList<int> UserIDs = GetSalesPerson(SBOCompany.UserSignature);
                        SAPbouiCOM.Conditions cons = new SAPbouiCOM.Conditions();
                        SAPbouiCOM.Condition con = cons.Add();
                        con.Alias = "slpCode";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        if (UserIDs.Count > 0)
                            con.CondVal = UserIDs[0].ToString();
                        else
                            con.CondVal = "-2";

                        for (int i = 1; i < UserIDs.Count; i++)
                        {
                            con.Relationship = SAPbouiCOM.BoConditionRelationship.cr_OR;
                            con = cons.Add();
                            con.Alias = "slpCode";
                            con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                            con.CondVal = UserIDs[i].ToString();
                        }
                        CFL.SetConditions(cons);
                        //SBOApp.MessageBox(CFL.ObjectType);
                    }
                }
            }
            else
            {
                if (pVal.ItemUID == "15" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    SAPbouiCOM.Matrix omtx = CurrentForm.Items.Item("69").Specific;
                    int row = omtx.GetNextSelectedRow();
                    GetAddressInfo(row);
                    InvoiceInfoControls(CurrentForm, CurrentForm.Items.Item("Address"));
                }
                if (pVal.ItemUID == "69" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK)
                {
                    InvoiceInfoControls(CurrentForm, CurrentForm.Items.Item("Address"));
                }
            }
        }
        void B1Form_BusinessPartner_frm_MenuEvent(SAPBoAddon.B1AddonBase.B1MenuEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
                //上一条、下一条,//第一条、最后一条
                if (pVal.MenuUID == B1MenuTypes.ado_SYS_Previous || pVal.MenuUID == B1MenuTypes.ado_SYS_Next || pVal.MenuUID == B1MenuTypes.ado_SYS_First || pVal.MenuUID == B1MenuTypes.ado_SYS_Last)
                {
                    //判断当前用户是否是管理员
                    if (IsManager(SBOCompany.UserSignature))
                    {
                        BubbleEvent = true;
                        return;
                    }
                    //获取当前用户权限的销售员
                    IList<int> UserIDs = GetSalesPerson(SBOCompany.UserSignature);
                    //当前值
                    string CardCode = GetCurrentObjectKey(UserIDs, CurrentFormEx.BusinessObject.Key);
                    bool NextSalesCode = GetNextSalesCode(UserIDs, CardCode, pVal.MenuUID);
                    if (NextSalesCode == false)
                    {
                        BubbleEvent = false;
                        GotoNewObject(UserIDs, CardCode, CurrentFormEx.UniqueID, CurrentFormEx.DataBrowser.BrowseBy, pVal.MenuUID);
                    }
                    else
                        BubbleEvent = true;
                }
            }
        }
        #endregion

        #region 继承至基类
        protected override bool BeforeSaveCheckFormData()
        {
            return true;
        }

        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {
            if (frmEditMode == SAPBoAddon.frmItemEditMode.fe_AddMode)
                InitPB();
        }

        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            this.FormSetting.FormType = B1FormTypes.sys_BusinessPartnerMasterData;
        }

        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {
        }
        #endregion
        #region Metods
        private void GetAddressInfo(int row)
        {
            #region 加载地址信息
            SAPbouiCOM.Matrix omtx = CurrentForm.Items.Item("69").Specific;
            CardCode = SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "5").ToString();
            CardCodeLineNum = omtx.GetCellSpecific("20", row).Value.ToString();
            AdresType = omtx.GetCellSpecific("53", row).Value.ToString();
            Address = "";
            foreach (AddressInfo oAdresInfo in AddressList)
            {
                if (CardCode == oAdresInfo.CardCode
                    && CardCodeLineNum == oAdresInfo.CardCodeLineNum
                    && AdresType == oAdresInfo.AdresType)
                {
                    CurrentForm.DataSources.UserDataSources.Item("Address").Value = oAdresInfo.Address;
                    return;
                }
            }

            SAPbobsCOM.Recordset ors = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            string SQL = string.Empty;
            SQL = "SELECT U_Address FROM CRD1 Where CardCode = '{0}' And Address='{1}' And AdresType = '{2}'";
            ors.DoQuery(string.Format(SQL, CardCode, CardCodeLineNum, AdresType));
            if (ors.RecordCount > 0)
            {
                Address = ors.Fields.Item("U_Address").Value;
                CurrentForm.DataSources.UserDataSources.Item("Address").Value = Address;
            }
            else
            {
                CurrentForm.DataSources.UserDataSources.Item("Address").Value = Address;
                return;
            }
            AddressInfo oAddressinfo = new AddressInfo();
            oAddressinfo.CardCode = CardCode;
            oAddressinfo.CardCodeLineNum = CardCodeLineNum;
            oAddressinfo.AdresType = AdresType;
            oAddressinfo.Address = Address;
            AddressList.Add(oAddressinfo);
            #endregion
        }
        private void InitPB()
        {
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            #region 页签选择
            //SAPbouiCOM.Folder oFolder;            
            //oFolder = oForm.Items.Item("13").Specific;
            //oFolder.Select();
            #endregion
            #region 添加字段
            SAPbouiCOM.Item oItem = null;
            try
            {
                oItem = oForm.Items.Item("Address");
                InvoiceInfoControls(oForm, oItem);
            }
            catch
            {

                oItem = oForm.Items.Add("Address", SAPbouiCOM.BoFormItemTypes.it_EXTEDIT);
                SAPbouiCOM.Item oRefItem = oForm.Items.Item("144");
                oItem.Top = oRefItem.Top;
                oRefItem = oForm.Items.Item("10001019");
                oItem.Left = oRefItem.Left;
                oRefItem = oForm.Items.Item("178");
                oItem.FromPane = 7;
                oItem.ToPane = 7;
                oItem.Width = oRefItem.Width;
                oItem.Height = 130;
                SAPbouiCOM.EditText oEdit = oItem.Specific;
                CurrentForm.DataSources.UserDataSources.Add("Address", SAPbouiCOM.BoDataType.dt_LONG_TEXT);
                oEdit.DataBind.SetBound(true, "", "Address");
                SAPbouiCOM.Matrix omtx = oRefItem.Specific;
                foreach (SAPbouiCOM.Column oCol in omtx.Columns)
                {
                    if (oCol.UniqueID != "1")
                    {
                        oCol.Visible = false;
                    }
                }
            }
            #endregion
            AddressList.Clear();
        }
        /// <summary>
        /// 控制发票信息是否显示
        /// </summary>
        /// <param name="oForm"></param>
        /// <param name="oItem"></param>
        private void InvoiceInfoControls(SAPbouiCOM.Form oForm, SAPbouiCOM.Item oItem)
        {
            SAPbouiCOM.Matrix omtx = null;
            if (oForm.Items.Item("480002075").Visible)
            {
                oItem.Visible = false;
                omtx = oForm.Items.Item("178").Specific;
                omtx.Columns.Item("2").Visible = true;
                omtx.Columns.Item("3").Visible = true;
                omtx.Columns.Item("4").Visible = true;
                omtx.Columns.Item("5").Visible = true;
                omtx.Columns.Item("6").Visible = true;
                oForm.Items.Item("178").Height = 120;
            }
            else
            {
                if (oForm.PaneLevel == 7)
                    oItem.Visible = true;
                else
                    oItem.Visible = false;
                omtx = oForm.Items.Item("178").Specific;
                omtx.Columns.Item("2").Visible = false;
                omtx.Columns.Item("3").Visible = false;
                omtx.Columns.Item("4").Visible = false;
                omtx.Columns.Item("5").Visible = false;
                omtx.Columns.Item("6").Visible = false;
            }
        }
        private void SetAddressInfo()
        {
            #region 地址信息
            SAPbouiCOM.Matrix omtx = CurrentForm.Items.Item("178").Specific;
            CardCode = SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm, "5").ToString();
            CardCodeLineNum = omtx.GetCellSpecific("1", 1).Value.ToString();

            AdresType = omtx.GetCellSpecific("43", 1).Value.ToString();
            Address = CurrentForm.DataSources.UserDataSources.Item("Address").Value.ToString();

            AddressInfo oAddressinfo = new AddressInfo();
            oAddressinfo.CardCode = CardCode;
            oAddressinfo.CardCodeLineNum = CardCodeLineNum;
            oAddressinfo.AdresType = AdresType;
            oAddressinfo.Address = Address;
            foreach (AddressInfo oAdresInfo in AddressList)
            {
                if (oAddressinfo.CardCode == oAdresInfo.CardCode && oAddressinfo.CardCodeLineNum == oAdresInfo.CardCodeLineNum && oAddressinfo.AdresType == oAdresInfo.AdresType)
                {
                    oAdresInfo.Address = Address;
                    return;
                }
            }
#if DEBUG
            Console.WriteLine(oAddressinfo.CardCode + "  " + oAddressinfo.CardCodeLineNum + "   " + oAddressinfo.AdresType);
#endif
            AddressList.Add(oAddressinfo);
            #endregion

        }
        private void UpdateAddressInfo()
        {
            #region 更新地址信息
            try
            {
                SAPbobsCOM.Recordset ors = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                string SQL = string.Empty;
                if (SBOCompany.InTransaction == false) SBOCompany.StartTransaction();
#if DEBUG
                Console.WriteLine("更新条数：" + AddressList.Count.ToString());
#endif
                foreach (AddressInfo oAdresInfo in AddressList)
                {
                    SQL = "UPDATE CRD1 SET U_Address = N'{0}' Where CardCode = '{1}' And Address = '{2}' And AdresType = '{3}' ";
                    oAdresInfo.Address = oAdresInfo.Address.Replace("'", "''");
                    SQL = string.Format(SQL, oAdresInfo.Address, oAdresInfo.CardCode, oAdresInfo.CardCodeLineNum, oAdresInfo.AdresType);
#if DEBUG
                    Console.WriteLine(oAdresInfo.ToString());
                    Console.WriteLine(SQL);
#endif
                    ors.DoQuery(SQL);
                }
                if (SBOCompany.InTransaction) SBOCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                InitPB();
            }
            catch (Exception ex)
            {
                if (SBOCompany.InTransaction) SBOCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                throw (ex);
            }
            #endregion
        }

        /// <summary>
        /// 判断用户是不是超级用户
        /// </summary>
        /// <param name="UserSign"></param>
        /// <returns></returns>
        private bool IsManager(int UserSign)
        {
            string SQL = "SELECT * FROM OUSR Where UserID = {0} And SUPERUSER = 'Y'";
            SQL = String.Format(SQL, UserSign.ToString());
            SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            rs.DoQuery(SQL);
            if (rs.RecordCount > 0)
                return true;
            return false;
        }
        /// <summary>
        /// 目标SQL语句
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="UserIDs"></param>
        /// <param name="CardCode"></param>
        /// <returns></returns>
        private SAPbobsCOM.Recordset TargetSQL(string Command, IList<int> UserIDs, string CardCode = null)
        {
            string SQL = string.Empty;
            SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            switch (Command)
            {
                case B1MenuTypes.ado_SYS_Next:
                    SQL = @"

							SELECT TOP 1 * 
							FROM (
                                    SELECT Top 1 T0.CardCode,T0.SlpCode
                                    FROM OCRD T0
                                    Where T0.DocEntry > (
						                                    SELECT T0.DocEntry
						                                    FROM OCRD T0
						                                    Where T0.CardCode = '{0}'
					                                    )  And T0.SlpCode in ({1})
									UNION ALL
                                    SELECT Top 1 T0.CardCode,T0.SlpCode
                                    FROM OCRD T0
                                    Where T0.SlpCode in ({1})			
									) T0	
                                    ";

                    break;
                case B1MenuTypes.ado_SYS_Previous:
                    SQL = @"
									SELECT Top 1 * 
									FROM ( 
										SELECT Top 1 T0.CardCode ,T0.SlpCode
										FROM OCRD T0
										Where T0.DocEntry < (
																SELECT T0.DocEntry
																FROM OCRD T0
																Where T0.CardCode = '{0}'
															)  And T0.SlpCode in ({1})
										UNION ALL
										SELECT Top 1 T0.CardCode ,T0.SlpCode
										FROM OCRD T0
										Where T0.SlpCode in ({1})
										) T0
                                    ";

                    break;
                case B1MenuTypes.ado_SYS_First:
                    SQL = @"

                                    SELECT Top 1 T0.CardCode ,T0.SlpCode
                                    FROM OCRD T0
                                    Where T0.SlpCode in ({1})
                                    Order By T0.DocEntry Asc
                                    ";
                    break;
                case B1MenuTypes.ado_SYS_Last:
                    SQL = @"

                                    SELECT Top 1 T0.CardCode ,T0.SlpCode
                                    FROM OCRD T0
                                    Where T0.SlpCode in ({1})
                                    Order By T0.DocEntry Desc
                                    ";
                    break;
            }
            string UserIDString = string.Empty;
            foreach (int UserID in UserIDs)
            {
                UserIDString += UserID.ToString() + ",";
            }
            if (UserIDString.Length > 0)
            {
                UserIDString = UserIDString.Substring(0, UserIDString.Length - 1);
            }
            else
                UserIDString = "-2";
            SQL = String.Format(SQL, CardCode, UserIDString);
            rs.DoQuery(SQL);
            return rs;
        }

        /// <summary>
        /// 目标SQL语句
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="UserIDs"></param>
        /// <param name="CardCode"></param>
        /// <returns></returns>
        private SAPbobsCOM.Recordset TargetSQL(string Command, string CardCode)
        {
            string SQL = string.Empty;
            SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            switch (Command)
            {
                case B1MenuTypes.ado_SYS_Next:
                    SQL = @"

                                    SELECT Top 1 T0.CardCode,T0.SlpCode
                                    FROM OCRD T0
                                    Where T0.DocEntry > (
						                                    SELECT T0.DocEntry
						                                    FROM OCRD T0
						                                    Where T0.CardCode = '{0}'
					                                    )

                                    ";

                    break;
                case B1MenuTypes.ado_SYS_Previous:
                    SQL = @"

                                    SELECT Top 1 T0.CardCode ,T0.SlpCode
                                    FROM OCRD T0
                                    Where T0.DocEntry < (
						                                    SELECT T0.DocEntry
						                                    FROM OCRD T0
						                                    Where T0.CardCode = '{0}'
					                                    ) 

                                    ";

                    break;
                case B1MenuTypes.ado_SYS_First:
                    SQL = @"

                                    SELECT Top 1 T0.CardCode ,T0.SlpCode
                                    FROM OCRD T0
                                    Order By T0.DocEntry Asc
                                    ";
                    break;
                case B1MenuTypes.ado_SYS_Last:
                    SQL = @"

                                    SELECT Top 1 T0.CardCode ,T0.SlpCode
                                    FROM OCRD T0
                                    Order By T0.DocEntry Desc
                                    ";
                    break;
            }
            string UserIDString = string.Empty;
            SQL = String.Format(SQL, CardCode, UserIDString);
            rs.DoQuery(SQL);
            return rs;
        }
        /// <summary>
        /// 跳转到新对象
        /// </summary>
        /// <param name="UserIDs"></param>
        /// <param name="CardCode"></param>
        /// <param name="FormUID"></param>
        /// <param name="ItemUID"></param>
        /// <param name="Command"></param>
        private void GotoNewObject(IList<int> UserIDs, string CardCode, string FormUID, string ItemUID, string Command)
        {
            SAPbobsCOM.Recordset rs;
            if (string.IsNullOrEmpty(CardCode))
                rs = TargetSQL(B1MenuTypes.ado_SYS_First, UserIDs);
            else
                rs = TargetSQL(Command, UserIDs, CardCode);
            if (rs.RecordCount <= 0)
            {
                SBOApp.SetStatusBarMessage("您没有浏览其他数据的权限，请与管理员联系进行权限分配。。");
                return;
            }
            SAPbouiCOM.Form oForm = SBOApp.Forms.Item(FormUID);
            oForm.Mode = SAPbouiCOM.BoFormMode.fm_FIND_MODE;

            SAPbouiCOM.EditText oEdit = oForm.Items.Item(ItemUID).Specific;
            oEdit.Value = rs.Fields.Item("CardCode").Value;
            oForm.Items.Item("1").Click(SAPbouiCOM.BoCellClickType.ct_Regular);
        }
        //获取销售员
        private bool GetNextSalesCode(IList<int> UserIDs, string CardCode, string Command)
        {
            SAPbobsCOM.Recordset rs = TargetSQL(Command, CardCode);
            if (rs.RecordCount > 0)
            {
                int SlpCode = rs.Fields.Item("SlpCode").Value;
                if (UserIDs.Contains(SlpCode))
                    return true;
                return false;
            }
            return false;
        }
        /// <summary>
        /// 获取当前对象的关键值
        /// </summary>
        /// <param name="UserIDs"></param>
        /// <param name="ObjectXml"></param>
        /// <returns></returns>
        private string GetCurrentObjectKey(IList<int> UserIDs, string ObjectXml)
        {
            string ObjectKey = string.Empty;
            if (string.IsNullOrEmpty(ObjectXml))
            {
                return "";
            }
            else
            {
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(ObjectXml);
                ObjectKey = xml.SelectSingleNode("*").SelectSingleNode("*").InnerText;//.SelectNodes("*")[0].InnerText;
            }
            return ObjectKey;
        }
        //获取销售员
        private IList<int> GetSalesPerson(int UserID)
        {
            IList<int> UserIDs = new List<int>();
            string SQL = @"
                                    SELECT T0.UserID,T1.SalesPrson,T2.role,T3.teamID,t3.descriptio,T3.U_FatherID
                                    FROM OUSR T0
	                                    INNER JOIN OHEM T1 ON T0.USERID = T1.userId
	                                    INNER JOIN HTM1 T2 ON T1.empID = T2.empID
	                                    INNER JOIN OHTM T3 ON T2.teamID = T3.teamID
                                    Where T0.UserID = {0}
                                    ";
            SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            SQL = string.Format(SQL, UserID);
            rs.DoQuery(SQL);
            if (rs.RecordCount > 0)
            {
                int slpcode = rs.Fields.Item("SalesPrson").Value;
                UserIDs.Add(slpcode);
                if (rs.Fields.Item("role").Value == "L")
                {
                    string descriptio = rs.Fields.Item("descriptio").Value;
                    SQL = @"
                                SELECT T0.UserID,T0.User_Code,T0.U_Name,T1.SalesPrson,T2.role,T3.teamID,t3.descriptio,T3.U_FatherID
                                FROM OUSR T0
	                                INNER JOIN OHEM T1 ON T0.USERID = T1.userId
	                                INNER JOIN HTM1 T2 ON T1.empID = T2.empID
	                                INNER JOIN OHTM T3 ON T2.teamID = T3.teamID
                                Where cast(T3.descriptio as nvarchar(30)) = '{0}' And T0.UserID <> {1}
                                ";
                    SQL = string.Format(SQL, descriptio, rs.Fields.Item("UserID").Value);
                    rs.DoQuery(SQL);
                    for (int i = 0; i < rs.RecordCount; i++)
                    {
                        slpcode = rs.Fields.Item("SalesPrson").Value;
                        UserIDs.Add(slpcode);
                        rs.MoveNext();
                    }

                    IList<string> UseTeams = new List<string>();
                    GetTeam(UseTeams, descriptio);
                    foreach (string team in UseTeams)
                    {
                        SQL = @"
                                SELECT T0.UserID,T0.User_Code,T0.U_Name,T1.SalesPrson,T2.role,T3.teamID,t3.descriptio,T3.U_FatherID
                                FROM OUSR T0
	                                INNER JOIN OHEM T1 ON T0.USERID = T1.userId
	                                INNER JOIN HTM1 T2 ON T1.empID = T2.empID
	                                INNER JOIN OHTM T3 ON T2.teamID = T3.teamID
                                Where cast(T3.descriptio as nvarchar(30)) = '{0}'
                                ";
                        SQL = string.Format(SQL, team);
                        rs.DoQuery(SQL);
                        for (int i = 0; i < rs.RecordCount; i++)
                        {
                            slpcode = rs.Fields.Item("SalesPrson").Value;
                            UserIDs.Add(slpcode);
                            rs.MoveNext();
                        }
                    }
                }
            }
            return UserIDs;
        }
        //获取团队 
        private void GetTeam(IList<string> UseTeam, string GroupID)
        {
            string SQL = "SELECT descriptio FROM OHTM T0 Where T0.U_FatherID = '{0}'";
            SQL = string.Format(SQL, GroupID);
            SAPbobsCOM.Recordset rs = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            rs.DoQuery(SQL);
            for (int i = 0; i < rs.RecordCount; i++)
            {
                string teamID = rs.Fields.Item("descriptio").Value;
                UseTeam.Add(teamID);
                GetTeam(UseTeam, teamID);
                rs.MoveNext();
            }
        }
        #endregion
    }
    class AddressInfo
    {
        public string CardCode;
        public string CardCodeLineNum;
        public string AdresType;
        public string Address;

        public override string ToString()
        {
            return CardCode + "  " + CardCodeLineNum + "   " + AdresType + "   " + Address;
        }
    }
}
